package com.cisco.pso;

import java.io.Reader;

public class PsoFileListReader extends FileListReader {

	protected String site;

	public PsoFileListReader(Reader reader, String site) {
		super(reader);

		this.site = site;

		for (int i = 0; i < items.size(); i++) {
			// replace with PSO item
			FileItem fi = items.get(i);

			String line = fi.fullName;
			PsoFileItem psoItem = new PsoFileItem(line, getShortName(line),
					getBaseName(line));

			items.set(i, psoItem);
		}
	}

	private String getBaseName(String fullName) {
		String shortName = getShortName(fullName);
		String lowerCaseShortName = shortName.toLowerCase();
		String lowerCaseSite = site.toLowerCase();

		if (lowerCaseShortName.startsWith(lowerCaseSite + "_")) {
			// non Camel naming, jsp file
			return shortName.substring((site + "_").length());
		} else if (lowerCaseShortName.startsWith(lowerCaseSite)) {
			// camel naming, Java file
			return shortName.substring(site.length());
		} else
			return shortName;
	}

}
